# 遵循编程规则，尽量使代码优美如诗
# from time import sleep
#
# from tqdm import trange, tqdm
#
# from tqdm.notebook import tqdm
#
# for i in tqdm(range(3,colour='blue')):
#     sleep(1)
#     print(i)

# class Dog:
#     '''一次模拟小狗的简单尝试'''
#     def __init__(self,name,age):
#         '''初始化属性 name和age'''
#         self.name = name
#         self.age = age
#
#     def sit(self):
#         '''模拟小狗收到命令时蹲下'''
#         print(f"{self.name} is now sitting.")
#
#     def roll_over(self):
#         '''模拟小狗收到命令时打滚'''
#         print(f"{self.name} rolled over!")
#
#
# my_dog = Dog('willie',6)
# print(f"my dog name is {my_dog.name}")
#
# my_dog.sit()
# my_dog.roll_over()


class Car:
    '''一次模拟汽车的简单尝试'''
    def __init__(self,make,modle,year=99):
        '''初始化描述汽车的属性'''
        self.make = make
        self.modle = modle
        self.year = year
        self.odometer_reading = 30


    def get_descriptive_name(self):
        '''返回整洁的描述性信息'''
        long_name = f"{self.year} {self.make} {self.modle}"
        return long_name.upper()


    def read_odometer(self):
        '''打印一条指出汽车里程的消息'''
        print(f"This car has {self.odometer_reading} miles on it.")


    def update_odometer(self,mileage):
        '''
        将里程表读数设置为指定的值
        禁止将里程表数往回调
        '''
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print('You can not roll back an odomete')


    def increment_odometer(self,miles):
        '''将里程表读数增加指定的量'''
        if miles >= 0:
            self.odometer_reading += miles
        else:
            print('go out!')


    def fill_gas_tank(self):
        '''电动汽车没有邮箱'''
        print(f"This {self.make} doesn't need a gas tank!")


my_new_car = Car('bwm','x1')
print(my_new_car.get_descriptive_name())
my_new_car.read_odometer()

# 通过实例修改属性的指
my_new_car.odometer_reading = 24
my_new_car.read_odometer()

# 通过方法修改属性的值
my_new_car.update_odometer(23_500)
my_new_car.read_odometer()

# 通过方法对属性的值进行递增
my_new_car.increment_odometer(100)
my_new_car.read_odometer()
my_new_car.fill_gas_tank()


class Battery:
    '''一次模拟电动汽车电瓶的简单尝试'''

    def __init__(self, battery_size=75):
        '''初始化电瓶的属性'''
        self.battery_size = battery_size

    def describe_battery(self):
        '''打印一条描述电瓶容量的消息'''
        print(f"This car has a {self.battery_size}-kwh battery.")

    def get_range(self):
        '''打印一条消息，指出电瓶的续航里程'''
        if self.battery_size == 75:
            range = 260
        elif self.battery_size == 100:
            range = 315

        print(f"This car can go about {range} miles on a full charge.")


class ElectricCar(Car):
    '''电动汽车的独特之处'''
    def __init__(self,make,model,year):
        '''
        初始化父类的属性
        再初始化电动汽车特有的属性
        '''
        super().__init__(make,model,year)
        # self.battery_size = 85
        # 将实例用作属性
        self.battery = Battery()


    # def describe_battery(self):
    #     '''打印一条描述电瓶容量的信息'''
    #     print(f"This car has a {self.battery_size}-kwh battery.")


    # 重写子类方法，此函数名与父类函数名相同，但会执行子类的方法，不会考虑父类的方法
    def fill_gas_tank(self):
        '''电动汽车没有邮箱'''
        print(f"This {self.make} doesn't need a gas tank!")


    def fill_gas_tanks(self):
        '''电动汽车没有邮箱'''
        print(f"This car doesn't need a gas tank!")

my_tesla = ElectricCar('tesla','model-s',2019)
print(my_tesla.get_descriptive_name())
#
# my_tesla.fill_gas_tank()
# my_tesla.fill_gas_tanks()
#
# my_tesla.battery.describe_battery()
# my_tesla.battery.get_range()


